<template>
	<view class="content">
		<!-- <u-navbar bgColor="#fff" :fixed="true" @leftClick="$back" title="dream约文" titleStyle="{'color': '#000'}">
			
		</u-navbar> -->
		<view class="baibox">
			<!-- <input type="text" maxlength="12" class="put" placeholder="请输入需求标题(最多12个字)" v-model="form.title"> -->
			<textarea class="area" maxlength="200" placeholder="请输入详细的制作要求" v-model="form.row"></textarea>
		</view>
		<view class="subbox" @click="submit">
			提交
		</view>
	</view>
</template>
<script>
	import * as db from '@/common/db.js'
	export default {
		data() {
			return {
				form: {
					title: "",
					row: ""
				},
				// 选择圈子
				quanshow: false,
				keyword: '',
				groupList: {},
				group_name: '',
				// 标签
				show: false,
				tags: [],
				tag: '',
				isEdit:false,
				isClick:false,
				type:0,
				fileList2: []
			}
		},
		onLoad() {
			console.log(11);
			
			this.form.row = uni.getStorageSync('order_desc');
			
		},
		methods: {
			submit() {
				uni.setStorageSync('order_desc', this.form.row);
				uni.navigateBack({//返回上一个页面
					delta: 1
				});
				// let auth = db.get('auth');
				// console.log(auth,777777777)
				// //用户存在，不跳转，不存在直接跳转
				// if (!auth) {
				// 	// toLogin()
				// 	uni.reLaunch({
				// 		url: '/pages/login/login'
				// 	})
				// 	return;
				// }
				
				// if (this.isClick) {
				// 	return; // 如果已经禁止点击，则直接返回
				// }
				// this.isClick = true
				// if (this.isClick) {
				// 	this.$api.default.request('Discover/addArticle', this.form, 'POST').then((res) => {
				// 		if (res.code) {
				// 			this.$common.successToShow(res.msg, () => {
				// 				uni.redirectTo({
				// 					url: '/pages/find/content?id=' + res.data.id
				// 				})
				// 			})
				// 		}
				// 	})
				// }
			},
			getGroupList() {
				this.$api.default.request('Discover/hotList', {
					keyword: this.keyword,
					limit: 999
				}, 'POST').then((res) => {
					if (res.code) {
						this.groupList = res.data
					}
				})
			},
			addTag() {
				let auth = db.get('auth');
				console.log(auth,777777777)
				//用户存在，不跳转，不存在直接跳转
				if (!auth) {
					// toLogin()
					uni.navigateTo({
						url: '/pages/login/login'
					})
					return;
				}
				
				if (this.tag == '') {
					this.$common.errorToShow('请填写标签内容')
					return
				}
				var is = true
				this.form.tags.forEach(item => {
					if (item === this.tag) {
						is = false
						this.$common.errorToShow('请勿重复添加')
						return
					}
				})
				
				if (this.form.tags.length >= 5) {
					is = false
					this.$common.errorToShow('最多添加5个标签')
					return
				}
				
				if (is) {
					this.form.tags.push(this.tag)
				}
				this.tag = ''
			},
			delTag(index) {
				let auth = db.get('auth');
				console.log(auth,777777777)
				//用户存在，不跳转，不存在直接跳转
				if (!auth) {
					// toLogin()
					uni.navigateTo({
						url: '/pages/login/login'
					})
					return;
				}
				
				this.form.tags.splice(index, 1)
			},

			//选择圈子弹框
			quanclose() {
				let auth = db.get('auth');
				console.log(auth,777777777)
				//用户存在，不跳转，不存在直接跳转
				if (!auth) {
					// toLogin()
					uni.navigateTo({
						url: '/pages/login/login'
					})
					return;
				}
				this.quanshow = false
			},
			//选择标签弹框
			open() {
				// console.log('open');
			},
			close() {
				this.show = false
			},

			// 删除图片
			deletePic(index) {
				this.form.img.splice(index, 1)
				this.fileList2.splice(index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this.form.img.length
				lists.map((item) => {
					this.form.img.push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this.form.img[fileListLen]
					this.form.img.splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: this.uploadImgUrl, // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							let datas = JSON.parse(res.data)
							this.fileList2.push(datas.url)
							setTimeout(() => {
								resolve(datas.url)
							}, 300)
						}
					});
				})
			},
			onChooseImg() {
				let auth = db.get('auth');
				console.log(auth,777777777)
				//用户存在，不跳转，不存在直接跳转
				if (!auth) {
					// toLogin()
					uni.navigateTo({
						url: '/pages/login/login'
					})
					return;
				}
				this.$common.chooseImage({}, (data) => {
					if (data) {
						this.form.img.push(data)
					}
				}, 9)
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: rgba(242, 245, 242, 1);
	}

	.content {
		padding-top: 18rpx;

		.baibox {
			background-color: #ffffff;
			padding: 40rpx 60rpx 20rpx;
			margin-bottom: 20rpx;

			.imgView {
				display: flex;
				align-items: center;
				flex-wrap: wrap;
				.imgList:nth-child(3n){
					margin-right: 0;
				}
				.imgList {
					position: relative;
					padding-bottom: 10rpx;
					margin-right: 31rpx;
					.imgClose {
						position: absolute;
						top: -8px;
						right: -8px;
						z-index: 1;
						width: 36rpx;
						height: 36rpx;
						background-color: #45C4B0;
						color: #fff;
						line-height: 36rpx;
						text-align: center;
						border-radius: 100px;
					}
				}

				.imgList:not(:first-child) {
					// margin-left: 15rpx;
				}
			}

			.put {
				width: 610rpx;
				font-size: 28rpx;
				color: #3d3d3d;
				padding: 0 8rpx 20rpx;
				border-bottom: 1px solid rgba(153, 153, 153, 0.1);
			}

			.area {
				width: 610rpx;
				padding: 20rpx 8rpx;
				max-height: 500rpx;
				min-height: 200rpx;
				resize: none;
				font-size: 28rpx;
				color: #3d3d3d;
			}

			.waibox {
				display: flex;
			}

			.zebox {
				margin-top: 20rpx;
				height: 38rpx;
				border-radius: 18px;
				opacity: 1;
				background: rgba(153, 153, 153, 0.1);
				display: flex;
				align-items: center;
				justify-content: center;
				padding: 0 15rpx;

				.zepic {
					width: 32rpx;
					height: 32rpx;
				}

				.zetxt {
					font-size: 24rpx;
					font-weight: normal;
					letter-spacing: 0.08em;
					color: #3D3D3D;
					padding-left: 8rpx;

					.tags:not(:first-child) {
						padding-left: 10rpx;
					}
				}
			}
		}

		.subbox {
			width: 630rpx;
			height: 86rpx;
			border-radius: 8px;
			opacity: 1;
			background: #45C4B0;
			text-align: center;
			margin: 0 auto;
			line-height: 86rpx;
			font-size: 32rpx;
			font-weight: bold;
			color: #FFFFFF;
		}

		.mask {
			background: #F2F5F2;
			border-top-left-radius: 8px;
			border-top-right-radius: 8px;
			overflow: hidden;

			.manei {
				background-color: #ffffff;
				padding: 0 20px 40rpx;

				.matitle {
					font-size: 28rpx;
					font-weight: bold;
					letter-spacing: 0em;
					color: #3D3D3D;
					text-align: center;
					padding: 20rpx 0 32rpx;
				}

				.soubox {
					height: 100rpx;
					border-radius: 4px;
					padding: 0 40rpx;
					display: flex;
					align-items: center;
					opacity: 1;
					background: #F6F7F9;

					.soupic {
						width: 32rpx;
						height: 32rpx;
						flex-shrink: 0;
					}

					.souput {
						flex-grow: 1;
						padding-left: 12rpx;
						font-size: 28rpx;
						font-weight: normal;
						letter-spacing: 0em;
						color: #999999;
					}
				}

				.huli {
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding: 0 30rpx;
					border-bottom: 1px solid rgba(153, 153, 153, 0.1);
					height: 134rpx;
					background-color: #ffffff;

					.head {
						width: 100rpx;
						height: 100rpx;
						border-radius: 50%;
						flex-shrink: 0;
					}

					.quanhead {
						width: 100rpx;
						height: 100rpx;
						border-radius: 12px;
						flex-shrink: 0;
					}

					.hucen {
						padding: 0 12rpx;
						flex-grow: 1;

						.hutitle {
							font-size: 28rpx;
							font-weight: bold;
							letter-spacing: 0em;
							color: #3D3D3D;
							padding-bottom: 8rpx;
						}

						.hutxt {
							font-size: 20rpx;
							color: #999999;

							text {
								padding-left: 20rpx;
								font-size: 20rpx;
								color: #999999;
							}
						}
					}

					.join {
						width: 104rpx;
						height: 40rpx;
						border-radius: 4px;
						opacity: 1;
						background: #45C4B0;
						text-align: center;
						line-height: 40rpx;
						font-size: 24rpx;
						font-weight: bold;
						color: #FFFFFF;
						flex-shrink: 0;
					}
				}

				.huli:last-child {
					border-bottom: none;
				}

				.zebox {
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding-bottom: 20rpx;

					.zetitle {
						font-size: 28rpx;
						font-weight: bold;
						letter-spacing: 0em;
						color: #3D3D3D;
					}

					.zetxt {
						font-size: 20rpx;
						font-weight: normal;
						text-align: right;
						letter-spacing: 0em;
						color: #999999;
					}

					.zengtxt {
						font-size: 28rpx;
						font-weight: normal;
						letter-spacing: 0em;
						color: #1DB994;
					}
				}

				.biaobox {
					display: flex;
					align-items: center;
					flex-wrap: wrap;
					padding-bottom: 10rpx;

					.biaoli {
						padding: 0 10rpx;
						height: 38rpx;
						border-radius: 180px;
						opacity: 1;
						background: #1DB994;
						margin: 0 20rpx 10rpx 0;
						display: flex;
						align-items: center;
						justify-content: center;

						.btxt {
							font-size: 24rpx;
							font-weight: bold;
							letter-spacing: 0.08em;
							color: #FFFFFF;
							padding-right: 5rpx;
						}

						.baix {
							width: 24rpx;
							height: 24rpx;
						}
					}
				}

				.rubox {
					height: 150rpx;
					border-radius: 4px;
					opacity: 1;
					background: #F6F7F9;

					.area {
						padding: 20rpx 40rpx;
						font-size: 28rpx;
						letter-spacing: 0em;
						color: #333333;
						max-height: 60rpx;
					}

					.shutxt {
						font-size: 28rpx;
						font-weight: normal;
						text-align: right;
						letter-spacing: 0em;
						padding-right: 40rpx;
						color: #999999;
					}
				}
			}

			.qubox {
				margin-top: 20rpx;
				height: 120rpx;
				opacity: 1;
				background: #FFFFFF;
				display: flex;
				align-items: center;
				justify-content: center;

				.subbox {
					width: 630rpx;
					height: 80rpx;
					border-radius: 8px;
					opacity: 1;
					background: #45C4B0;
					font-size: 32rpx;
					line-height: 80rpx;
					font-weight: bold;
					text-align: center;
					letter-spacing: 0em;
					color: #FFFFFF;
				}
			}
		}
	}
</style>